#!/bin/bash

apt-get install isc-dhcp-server -y
nmcli con modify Wired\ connection\ 1 ipv4.addresses 10.222.222.1/24
nmcli con mod Wired\ connection\ 1 ipv4.method manual
nmcli con up Wired\ connection\ 1


cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd_bak.conf
cp /etc/default/isc-dhcp-server /etc/default/isc-dhcp-server_bak
cat > /etc/dhcp/dhcpd.conf <<eof
subnet 10.222.222.0 netmask 255.255.255.0 {
   range 10.222.222.2 10.222.222.254;
   option routers 10.222.222.1;
   option broadcast-address 10.222.222.255;
   default-lease-time 600;
   max-lease-time 7200;
}
eof

cat > /etc/default/isc-dhcp-server <<eof
# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)

# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid

# Additional options to start dhcpd with.
#        Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#        Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="eth0"
INTERFACESv6=""
eof

#启动
systemctl start isc-dhcp-server
#开机自启
systemctl enable isc-dhcp-server